<template>
  <div class="mult-picture">
    <div v-if="componentData.type === '1'" class="h5">
      <div class="block"></div>
      <div v-if="componentData.pdfZh" class="normal-header">
        <span>{{ componentData.titleZh }}</span>
        <div class="btn primary" @click="toContactUs">
          {{ lang === 'zh' ? '立即获取报价' : 'Get a quote' }}
        </div>
        <div class="btn" @click="handleDownload(componentData[`pdf${capitalizeLang}`])">
          {{ lang === 'zh' ? '下载PDF文档' : 'Download PDF' }}
        </div>
      </div>
      <div class="detail">
        <p class="ft-24">{{ componentData[`title${capitalizeLang}`] }}</p>
        <p class="ft-16">{{ componentData[`subtitle${capitalizeLang}`] }}</p>
        <p class="ft-12">{{ componentData[`descZh${capitalizeLang}`] }}</p>
      </div>
      <img v-if="componentData.pcImgZh" :src="componentData.pcImgZh" alt="solution" />
    </div>
    <div v-if="componentData.type === '2'" class="col">
      <img v-for="(item, index) in h5Img" :key="index" :src="item" class="col-img" alt="solution" />
    </div>
  </div>
</template>

<script>
import { mapGetters, mapState } from 'vuex'

export default {
  props: {
    componentData: {
      type: Object,
      default: () => ({}),
    },
    // 设备型号
    navigator: {
      type: String,
      default: '',
    },
  },
  data() {
    return {}
  },
  computed: {
    ...mapState(['lang', 'isZh']),
    ...mapGetters(['capitalizeLang']),
    h5Img() {
      let imgs = this.componentData[`h5Img${this.capitalizeLang}`]
      if (!this.componentData[`h5Img${this.capitalizeLang}`]) {
        imgs = this.componentData[`pcImg${this.capitalizeLang}`]
      }
      return imgs.split(',')
    },
  },
  methods: {
    async toContactUs() {
      if (this.isZh) {
        window.open('https://work.weixin.qq.com/ca/cawcdec2e016c3c426')
      } else {
        window.open('https://wa.me/8617782030739')
      }
    },
    handleDownload(url) {
      const name = url.split('/').pop()
      // 获取heads中的filename文件名
      const downloadElement = document.createElement('a')
      // 创建下载的链接
      downloadElement.href = url
      downloadElement.target = '_blank'
      // 下载后文件名
      downloadElement.download = name
      document.body.appendChild(downloadElement)
      // 点击下载
      downloadElement.click()
      // 下载完成移除元素
      document.body.removeChild(downloadElement)
    },
  },
}
</script>

<style lang="less" scoped>
@import '~assets/var';

.mult-picture {
  .h5 {
    position: relative;
    background-color: #fff;
    height: 900px;
    text-align: center;
    padding: 120px 0 0;
    overflow: hidden;

    .block {
      width: 100%;
      height: 48px;
    }

    .normal-header {
      width: 100%;
      height: 48px;
      padding: 0 12px;
      position: fixed;
      top: 50px;
      z-index: 20;
      background: #fff;
      border-radius: 4px;
      border-bottom: 1px solid #f6f4f4;

      span {
        font-size: 14px;
        line-height: 48px;
        color: #333;
        font-weight: 500;
        float: left;
      }

      .btn {
        font-size: 10px;
        height: 28px;
        line-height: 26px;
        padding: 0 10px;
        margin: 10px 0 0 10px;
        color: #0261bc;
        border: 1px solid #0261bc;
        border-radius: 20px;
        float: right;
        cursor: pointer;

        &.primary {
          background-color: #0261bc;
          color: #fff;
        }
      }
    }

    img {
      max-width: 680px;
      max-height: 680px;
      display: block;
      margin: 0 auto;
    }

    .ft-24 {
      font-size: 48px;
      color: #0762cb;
      font-weight: bold;
    }

    .ft-16 {
      font-size: 32px;
      line-height: 56px;
      color: #444;
      font-weight: bold;
    }

    .ft-12 {
      font-size: 24px;
      color: #666;
      font-weight: 400;
    }
  }

  .col {
    background-color: #fff;
    position: relative;
    overflow: hidden;
    min-height: 100px;

    .col-img {
      width: 100%;
      height: auto;
      display: block;
    }
  }
}
</style>
